package com.gxa.controller;


import com.gxa.common.uitls.R;
import com.gxa.entity.Index;
import com.gxa.service.SalesReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "销售报表接口")
public class SalesReportController {

    @Autowired
    private SalesReportService salesReportService;

    @GetMapping("/salesReport/incomExpend")
    @ApiOperation("查询一级分类的收入支出")
    public R incomExpend(){
        try {
            List<Index> incomOut = this.salesReportService.queryIncomExpendList();
            Map<String,Object> map = new HashMap<>();
            map.put("incomOut",incomOut);//收入和支出
            return R.ok(map);
        } catch (Exception e) {
            e.printStackTrace();

            return R.error("请求异常");
        }
    }

    @GetMapping("/salesReport/percentage")
    @ApiOperation("查询每类销售总金额百分比")
    public R percentage(){
        try {
            List<Index> indices = this.salesReportService.queryPercentageList();
            Map<String,Object> map = new HashMap<>();
            map.put("indices",indices);
            return R.ok(map);
        } catch (Exception e) {
            e.printStackTrace();

            return R.error("请求异常");
        }
    }
}
